﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace UI
{
    public class RecycleResetSelectTreaPanel : RecycleResetSelectHeroPanel 
    {
        public override void SortItem(List<GameObject> objs)
        {
            objs.Sort(delegate (GameObject x, GameObject y) {
                return -x.GetComponent<RecycleSelectTreasureItem>().CompareTo(y.GetComponent<RecycleSelectTreasureItem>());
            });
        }

        public override bool IsItemSelected(object item)
        {
            UITreasure trea = item as UITreasure;
            if (selectCache.Contains(trea.guid))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public override List<object> GetCanSelectItems()
        {
            List<object> res = new List<object>();
            foreach (var item in StaticData.playerData.InstPlayerData.GetUITreasureByType(0))
            {
                if (item.owner != null)
                {
                    continue;
                }
                if (item.IsZeroTreasure())
                {
                    continue;
                }
                res.Add(item);
            }
            return res;
        }

        public override void ShowSelectMaxTip()
        {
            BoxManager.CreatePopupTextBox(TableTextBlo.GetText("recycle_select_reset_trea_warning"));
        }

        public override GameObject CreateSelectItem(object obj)
        {
            UITreasure trea = obj as UITreasure;
            GameObject select = null;
            foreach (var item in cachedObjs)
            {
                if (item.GetComponent<RecycleSelectItemBase>().GetItemGUID() == trea.guid)
                {
                    select = item;
                    break;
                }
            }
            if (select != null)
            {
                cachedObjs.Remove(select);
                return select;
            }
            else
            {
                return GameObject.Instantiate(itemPrefab) as GameObject;
            }
        }
    }

}